
<!-- saved from url=(0057)http://andrear.altervista.org/contents/pc/anagram-js.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>A Javascript Anagram Generator</title>
	
</head>
<body>

<h3>My own anagram generator</h3>


<script>
	var str,re,cnt,cntmax;

	function rst(){
		cnt=0; 
                cntmax=10000; 
                str="";
		re=null;
	}

	function go(prefix, postfix){
            console.log("_____in go"+"  prefix1: "+prefix+"  postfix1: "+postfix);
            
		if (cnt>=cntmax) return;
		if (postfix==""){
                        console.log("___adding:"+prefix);
                        str+=prefix+"\r\n"; 
                        cnt++;
                        //return;
		}
		for (var i=0;i<postfix.length;i++){
			var prefix2=prefix+postfix.charAt(i);
                        
			var postfix2=postfix.substring(0,i)+postfix.substring(i+1);
                        console.log("  postfix2: "+postfix2+"  prefix2: "+prefix2);
			go(prefix2,postfix2);
		}
                
                console.log("____exit go()");
	}
        
        
        function doit(){
            rst(); go("", "1234567800393939393939"); 
           
        // tout.value=str; 
        console.log(str)    
        window.alert("Anagrams: "+cnt)
            
        }
        
        doit();
</script>

</body></html>